//
//  VCOfPhoto.m
//  SeeTheWorld
//
//  Created by dllo on 16/3/4.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "VCOfPhoto.h"
#import "PCH.pch"
#import <UIImageView+WebCache.h>


@interface VCOfPhoto ()

@property (nonatomic, retain)UIButton *buttonOfLeft;


@end

@implementation VCOfPhoto

- (void)dealloc {
    [_buttonOfLeft release];
    [_photo release];
    [_note release];
    [super dealloc];
}

- (void)viewWillAppear:(BOOL)animated {
    self.tabBarController.tabBar.hidden = YES;
    self.navigationController.navigationBar.hidden = YES;
}

- (void)viewWillDisappear:(BOOL)animated {
    self.tabBarController.tabBar.hidden = NO;
    self.navigationController.navigationBar.hidden = NO;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor blackColor];
    
    /** 主页navigation左侧button */
    self.buttonOfLeft = [UIButton buttonWithType:UIButtonTypeCustom];
    self.buttonOfLeft.frame = CGRectMake(10, 20, 30, 30);
    [self.buttonOfLeft addTarget:self action:@selector(fanHui:) forControlEvents:UIControlEventTouchUpInside];
    [self.buttonOfLeft setBackgroundImage:[UIImage imageNamed:@"iconfont-fanhui-2"] forState:UIControlStateNormal];
    [self.view addSubview:self.buttonOfLeft];
    
    
    CGFloat x = self.image_width.floatValue;
    CGFloat y = self.image_height.floatValue;
    
    UIImageView *imageOfPhoto = [[UIImageView alloc] init];
    UILabel *label = [[UILabel alloc] init];
   
    /** 判断照片大小, 太高了就缩点 */
    if (y < 1200) {
        
        imageOfPhoto.frame = CGRectMake(0, 150, WIDTH, WIDTH / (x / y));
        label.frame = CGRectMake(10, 110, WIDTH - 20, 40);
        
    } else {
        
        imageOfPhoto.frame = CGRectMake(0, 150, WIDTH, WIDTH / (x / y) - 150);
        label.frame = CGRectMake(10, 110, WIDTH - 20, 40);

    }
    
    [self.view addSubview:imageOfPhoto];
    [imageOfPhoto sd_setImageWithURL:[NSURL URLWithString:self.photo]];
    [imageOfPhoto release];
    imageOfPhoto.userInteractionEnabled = YES;
    
    [self.view addSubview:label];
    label.text = [self.note objectForKey:@"trip_name"];
    label.textColor = [UIColor whiteColor];
    label.font = [UIFont systemFontOfSize:20];
    label.textAlignment = 1;
    [label release];
    
    /** 添加缩放手势 */
    UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pinchAction:)];
    [imageOfPhoto addGestureRecognizer:pinch];
    [pinch release];
    
    /** 添加拖动手势 */
    UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panAction:)];
  //  [imageOfPhoto addGestureRecognizer:pan];
    [pan release];
}

/** 实现拖动手势 */
- (void)panAction:(UIPanGestureRecognizer *)pan {
    NSLog(@"aa");
    /** 更改 self.imageView.transform属性 */
    CGPoint point = [pan translationInView:pan.view];
    pan.view.transform = CGAffineTransformTranslate(pan.view.transform, point.x, point.y);
    
    /** 参考点归0. */
    [pan setTranslation:CGPointZero inView:pan.view];
    
}

/** 实现缩放手势 */
- (void)pinchAction:(UIPinchGestureRecognizer *)pinch {
    /** 修改self.imageView.transform属性 */
    pinch.view.transform = CGAffineTransformScale(pinch.view.transform, pinch.scale, pinch.scale);

    /** 缩放因子 归1 */
    pinch.scale = 1;
}

- (void)fanHui:(UIButton *)button {
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
